<template>
    <view class="container">
        <view class="menu">
            <view class="cell-group">
                <easy-cell-item
                    icon="icon-gerenxinxi"
                    label="供应商信息"
                    @click.native="easyGoTo('/pages_supplier/packet/setting/info')"></easy-cell-item>
                <easy-cell-item
                    icon="icon-mima-xi"
                    label="修改密码"
                    @click.native="easyGoTo('/pages_supplier/packet/setting/changePwd')"></easy-cell-item>
                <easy-cell-item
                    icon="icon-yifahuo"
                    label="发货地址"
                    @click.native="easyGoTo('/pages_supplier/packet/setting/address')"></easy-cell-item>
                <easy-cell-item
                    @click.native="checkVersion"
                    @longpress.native="longpress"
                    icon="icon-banben"
                    :value="getVersion()"
                    label="检查版本"></easy-cell-item>
                <easy-cell-item v-if="false" icon="icon-qingchu" label="清除缓存"></easy-cell-item>
            </view>
            <button class="btn btn-success-hollow" @click="logout">退出登录</button>
            <view class="tip">
                <text>如需要注销账号，请联系客服人员</text>
            </view>
        </view>
        <uni-popup ref="popLogout" type="bottom" background-color="#fff" :safe-area="false">
            <view class="bottom-pop">
                <text class="title">确认退出当前账户?</text>
                <view class="actions">
                    <button class="btn btn-gray-hollow" @click="closePop">取消</button>
                    <button class="btn btn-danger-hollow" @click="doLogout">退出</button>
                </view>
            </view>
        </uni-popup>
        <uni-popup ref="popServe" type="bottom" background-color="#fff" :safe-area="false">
            <view class="bottom-pop">
                <text class="title">切换环境</text>
                <view class="actions">
                    <button class="btn btn-gray-hollow" @click="selectServer(1)">正式</button>
                    <button class="btn btn-gray-hollow" @click="selectServer(9)">测试</button>
                </view>
            </view>
        </uni-popup>
        <app-version ref="appVersion" :isAutoCheck="false" :appId="getAppId()"></app-version>
    </view>
</template>
<script>
import { mapMutations, mapState } from "vuex"
import storage from "@/uni-sub-base/utils/storage.js"
import easyCellItem from "@/pages_supplier/components/easy/easy-cell-item.vue"
import appVersion from "@/uni-sub-base/module/version/app-version.vue"
export default {
    components: {
        easyCellItem,
        appVersion,
    },
    data() {
        return {}
    },
    methods: {
        ...mapMutations(["SET_AUTH"]),
        goUrl(url) {
            this.easyGoTo(url)
        },
        //退出登录
        logout() {
            this.$refs.popLogout.open()
        },
        //退出登录
        doLogout() {
            this.closePop()
            this.SET_AUTH("")
            storage.removeCache("token")
            storage.removeCache("userInfo")
            this.easyReLaunch("/pages/login/index")
        },
        //关闭提示弹窗
        closePop() {
            this.$refs.popLogout.close()
        },
        getVersion() {
            //#ifdef APP-PLUS
            let ver = plus.runtime.version
            console.log(ver)
            return ver
            //#endif
            return ""
        },
        checkVersion() {
            this.$refs.appVersion.checkVersion()
        },
        longpress() {
            this.$refs.popServe.open()
        },
        selectServer(type) {
            //1正式 0 测试
            storage.setCache("appService", type)
            this.doLogout()
        },
    },
}
</script>

<style lang="scss">
.cell-group {
    margin-bottom: 20rpx;
    border-radius: 16rpx;
    overflow: hidden;
    background: #ffffff;
}
.menu {
    padding: 24rpx;
    .btn {
        margin: 46rpx 36rpx 0 36rpx;
    }
}

.bottom-pop {
    .actions {
        margin-top: 40rpx;

        .btn {
            height: 76rpx;
        }
    }
}
.tip {
    margin-top: 20rpx;
    display: flex;
    justify-content: center;

    text {
        font-size: 24rpx;
        color: $color-gray-2;
    }
}
</style>
